package com.edu.hre.struts.form.leave;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.struts.action.ActionForm;

import com.edu.hre.common.utils.CommonUtils;
import com.edu.hre.struts.action.leave.LeaveRequestUpdateAction;

public class LeaveApproveUpdateForm extends ActionForm{


	/**
	 * 
	 */
	private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
	private static final SimpleDateFormat dateFormat_ = new SimpleDateFormat("MM/dd/yyyy HH_:mm");
	private Integer id;
	private int empNum;
    private String empFullName;
    private String user;
    private Date firstLeave;
    private Date lastLeave;
    private int leaveTypeId;
    private Boolean approved;
    private String leaveType;
    private String empComment;
    private String supComment;
    private Float totalLeaved;
    
    private boolean isSelected = false;
	private String message = "";
	
	public LeaveApproveUpdateForm(){
		
	}
	
	public LeaveApproveUpdateForm(Integer id, Integer empNum, String empFullName, String user, Date firstLeave, 
			Date lastLeave, Boolean approved, String leaveType, String empComment, String supComment) {
		super();
		this.id = id;
		this.empNum = empNum;
		this.empFullName = empFullName;
		this.firstLeave = firstLeave;
		this.lastLeave = lastLeave;
		this.approved = approved;
		this.leaveType = leaveType;
		this.setEmpComment(empComment);
		this.setSupComment(supComment);
		this.user = user;
	} 
	
	public int getEmpNum() {
		return empNum;
	}

	public void setEmpNum(int empNum) {
		this.empNum = empNum;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Date getFirstLeave() {
		return firstLeave;
	}
	public void setFirstLeave(Date firstLeave) {
		this.firstLeave = firstLeave;
	}
	public Date getLastLeave() {
		return lastLeave;
	}
	public void setLastLeave(Date lastLeave) {
		this.lastLeave = lastLeave;
	}
	public String getLeaveType() {
		return leaveType;
	}
	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	} 
	public boolean isSelected() {
		return isSelected;
	}
	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Boolean getApproved() {
		return approved;
	}
	public void setApproved(Boolean approved) {
		this.approved = approved;
	}
	public String getEmpFullName() {
		return empFullName;
	}
	public void setEmpFullName(String empFullName) {
		this.empFullName = empFullName;
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getFirstLeaveStr() {
		if(this.firstLeave == null){
			return "";
		}
		return dateFormat_.format(this.firstLeave).replace("_", "h");
	}

	public void setFirstLeaveStr(String firstLeave) {
		try {
			this.firstLeave = dateFormat.parse(firstLeave);
		} catch (Exception e) { 
			CommonUtils.println(e.getMessage());
		}
	}

	public String getLastLeaveStr() {
		if(this.lastLeave == null){
			return "";
		}
		return dateFormat_.format(this.lastLeave).replace("_", "h");
	}

	public void setLastLeaveStr(String lastLeave) {
		try {
			this.lastLeave = dateFormat.parse(lastLeave);
		} catch (Exception e) { 
			CommonUtils.println(e.getMessage());
		}
	}

	public int getLeaveTypeId() {
		return leaveTypeId;
	}

	public void setLeaveTypeId(int leaveTypeId) {
		this.leaveTypeId = leaveTypeId;
	} 
	
	public Float getTotalLeaved() {
		if(totalLeaved != null){
			return totalLeaved;
		}
		try {
			return LeaveRequestUpdateAction.computeLeaveDays(firstLeave, lastLeave);	
		} catch (Exception e) {
			CommonUtils.println(e.getMessage());
		}
		return null;
	}

	public void setTotalLeaved(Float totalLeaved) {
		this.totalLeaved = totalLeaved;
	}
	
	public String getTotalLeavedThisTime(){
		DecimalFormat df = new DecimalFormat("0.0");
		return df.format(getTotalLeaved());
	}

	public String getSupComment() {
		return supComment;
	}

	public void setSupComment(String supComment) {
		this.supComment = supComment;
	}

	public String getEmpComment() {
		return empComment;
	}

	public void setEmpComment(String empComment) {
		this.empComment = empComment;
	} 
	
	public String getTotalPaidLeaved() {
		float totalPaidLeavedDays = LeaveRequestUpdateAction.getTotalPaidLeavedDays(empNum);
		float totalGrantPaidLeave = LeaveRequestUpdateAction.getTotalGrantedLeaveDays(empNum);
		String tmp = totalPaidLeavedDays + "/" + totalGrantPaidLeave;
		CommonUtils.println("getTotalPaidLeaved: " + tmp);
		return tmp;
	}

	public float getTotalOtherLeaved() {
		return LeaveRequestUpdateAction.getTotalOtherLeavedDays(empNum);
	} 

}
